<?php
/**
 * polwebgis
 * 
 * This file is part of polwebgis.
 *
 * @copyright   Copyright (c) 2012 Dominik Janisch (http://www.joanneum.at)
 * @lastmodified    $LastChangedDate: 2012-03-07 09:15:12 +0000 (Wed, 07 Mar 2012) $
 * @revision    $Revision: 160 $ 
 */

class LanguageHandler
{

    private $arr_language_strings_;
    private static $class_instance_;
    private static $instance_ = false;

    protected function __construct(){}
        
    public function __destruct(){}
    
    private function __clone(){}
    
    public static function getInstance()
    {
        if(!self::$instance_)
        {
            self::$class_instance_ = new LanguageHandler();
            self::$instance_ = true;
            return self::$class_instance_;
        }
        return self::$class_instance_;
    }
    
    public function assignLanguageFile($language_code, OutputHandler $output_handler)
    {
        $filename = PATH_TO_APP . "/language/" . $language_code . ".xml";
        $xml = @simplexml_load_file($filename);
        if(!$xml)
            return false;
        foreach($xml as $key => $value)
        {
            $output_handler->assignValuesToTemplate(array("language_" . $key => $value));
            $this->arr_language_strings_[$key] = $value;
        }
        return true;
    }
    
    public function getLanguageString($key)
    {
        if(isset($this->arr_language_strings_[$key]))
            return (string)$this->arr_language_strings_[$key];
        return false;
    }
}

?>
